﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class S2Click : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler
{

    public Texture2D TargetCursor;
    public Renderer s2Renderor;
    public Renderer ledRenderor;
    public Renderer ledRenderor1;
    public AudioClip kmAction;
    public AudioSource motoAudio;
    public GameObject led;
    // Use this for initialization
    void Start()
    {
        s2Renderor = this.gameObject.GetComponent<Renderer>();
        ledRenderor = GameObject.Find("H2_green").GetComponent<Renderer>();
        ledRenderor1 = GameObject.Find("H3_red").GetComponent<Renderer>();
        kmAction = Resources.Load("Audio/KmAction", typeof(AudioClip)) as AudioClip;
    }

    // Update is called once per frame
    void Update()
    {
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        Debug.Log("反转");
        if (Global.RunStatus==0 && Global.Q1Status==true)
        {
            AudioSource.PlayClipAtPoint(kmAction, this.transform.position);
            ledRenderor.material.color = new Color(0, 1f, 0, 255);
            ledRenderor1.material.color = new Color(0.5f, 0, 0, 255);
            motoAudio.loop = true;
            motoAudio.Play();
            Global.RunStatus=2;
        }
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        //把鼠标指针改为ClickedCursorImg
        TargetCursor = Resources.Load("Cursor/hand1", typeof(Texture2D)) as Texture2D;
        Cursor.SetCursor(TargetCursor, new Vector2(0, 0), CursorMode.Auto);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        // 重置鼠标指针图标
        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        s2Renderor.material.color = new Color(0, 0.5f, 0, 255);
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        s2Renderor.material.color = new Color(0, 255, 0, 255);
    }
}
